#ifndef     __MOTOR_H
#define     __MOTOR_H

#include "../utils/object.h"
#include "../utils/nocopyable.h"
#include "../utils/error.h"

namespace driver {

enum Dir_t {
    CW = 0,
    CCW = 1,
    Brake = 2,
    Release = 3,
};

class Motor_t {

public:
    static const uint32_t Timeout = 10 * 1000;

    Motor_t();

    static bool is_checked();
    static bool is_checked2();

    
    utils::Error_t run3();

    inline uint8_t status() { return m_err.value(); }

    inline bool is_raster_edge() { return m_raster_flag; }

    inline void set_flag() {
        m_raster_flag = true;
    }
    inline void clr_flag() {
        m_raster_flag = false;
    }

    static void set_dir(Dir_t dir);
private:
    utils::Error_t run();

    bool m_dir;
    volatile bool m_raster_flag;
    utils::Error_t m_err;
};

extern utils::Object<Motor_t> motor;

}


#endif
